# Maintainer: knuxify <knuxify@gmail.com>
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/cyanogenmod_baffinlite_defconfig

pkgname=linux-samsung-baffinlite
pkgver=3.4.5
pkgrel=5
pkgdesc="Samsung Galaxy Grand Neo kernel fork"
arch="armv7"
_carch="arm"
_flavor="samsung-baffinlite"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev xz gcc6"

# Compiler: GCC 6 (doesn't boot when compiled with gcc10+)
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_samsung_baffinlite"
_commit="6cd5888e4714454ca7398f46aa09fa29170d92b9"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/knuxdroid/$_repository/archive/$_commit.tar.gz
	$_config
	kernel-use-the-gnu89-standard-explicitly.patch
"
builddir="$srcdir/$_repository-$_commit"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
	make ARCH="$_carch" CC="${CC:-gcc}" CFLAGS_MODULE="-fno-pic" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" modules
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"

	# Modules
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1))-postmarketOS" \
		INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1 \
		modules_install
}

sha512sums="
0c1043e703bd9382db48d2f472abb8d0acee74ff16070daf03bef9d591d611aae45c0af09971111ef6b9f3fca6dcd3742e2318ef29a0cde13910983b20a65bbc  linux-samsung-baffinlite-6cd5888e4714454ca7398f46aa09fa29170d92b9.tar.gz
6565e18ba87da0304927c0f3b71c33e1056d6a989fece6df4f596d4855ed0e75c31c0809ad9dbad770cd0593410391d2cdb98016cc57ed654e1367b1ab8c5ced  config-samsung-baffinlite.armv7
ad0182a483791fc88e058838bc331b2f04a75ba291e763767babdb815efadfc3b4fda97e69e2e3f00a426cabea088e35297a92bd287592597d1e309be68ee92c  kernel-use-the-gnu89-standard-explicitly.patch
"
